package com.pattern.once.proxy.d;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class P2<T>  {

    private T tager;

    public P2(T tager) {
        this.tager = tager;
    }

    public <T> T newInstance(Class<T> tClass ){
        T o = (T) Proxy.newProxyInstance(tClass.getClassLoader(), new Class[]{tClass}, (proxy, method, args) -> {
            System.out.println("执行之前");
            Object invoke = method.invoke(tager, args);
            System.out.println("执行之后");
            return invoke;
        });
        return o;
    }
}
